<template>
    <div>
<h1>科室信息展示</h1>
科室名称：<input type="text" v-model="can.name">
创建时间区间：<input type="date" v-model="can.zao">--<input type="date" v-model="can.wan">
<input type="button" value="查询" @click="cha">
<input type="button" value="重置" @click="chong">

<a target="_blank" href="https://localhost:7120/api/KeShi/DaoC">导出科室信息</a>
<a href="/addks">新增科室</a>
<table class="table">
    <thead>
        <tr>
            <td>科室名称</td>
            <td>科室人数</td>
            <td>科室创建时间</td>
            <td>科室描述</td>
            <td>操作</td>
        </tr>
    </thead>
    <tbody>
         <tr v-for="a in da">
            <td>{{a.ksName}}</td>
            <td>{{a.ksCount}}</td>
            <td>{{a.ksCreateTime}}</td>
            <td>{{a.ksMiaoShu}}</td>
            <td>
                <input type="button" value="逻辑删除" @click="shan(a.kId)">
                <input type="button" value="修改" @click="xiu(a.kId)">
            </td>
        </tr>
    </tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
const uc=useRouter()

onMounted(()=>{
    showw();
})
//显示的m
const da=ref([
  {
    "kId": 1,
    "ksName": "",
    "ksCount": 0,
    "ksMiaoShu": "",
    "ksCreateTime": "2025-05-19T11:29:32.2299346",
    "ksIsDel": null
  }
])
//参数
const can=ref({
    name:"",
    zao:null,
    wan:null
})

const showw=()=>{
    axios.get("/api/KeShi/ShouKs",{params:can.value}).then(res=>{
        da.value=res.data
    })
}

const cha=()=>{
    showw()
}

const chong=()=>{
    can.value.name="",
    can.value.wan=null,
    can.value.zao=null
    showw()
}

//逻辑删除
const shan=(x:any)=>{
 if(!confirm("确定删除吗？")){
    return
 }

 axios.delete("/api/KeShi/DeleteKs",{params:{id:x}}).then(res=>{
    if(res.data>0){
        alert("删除成功");
        showw()
    }else{
        alert("删除失败")
    }
 })

}

 //跳修改
const xiu=(x:any)=>{
    uc.push({path:"/fanks",query:{id:x}})
}
</script>

<style scoped>

</style>
